<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/style.css"/>
    <script type="text/javascript" src="./Js/jquery.js"></script>
    <script type="text/javascript" src="./Js/bootstrap.js"></script>
    <script type="text/javascript" src="./Js/ckform.js"></script>
    <script type="text/javascript" src="./Js/common.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form action="" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover ">
        <tr>
            <td width="10%" class="tableleft">管理员编号</td>
            <td><input type="text" id="id" name="id" value="${userId}" readonly="readonly"/></td>
        </tr>
        <tr>
            <td class="tableleft">管理员名称</td>
            <td><input type="text" id="userName" name="username" value="${username}" readonly="readonly"/></td>
        </tr>
        <tr>
            <td class="tableleft">旧密码</td>
            <td><input type="password" id="password" name="password"/></td>
        </tr>
        <tr>
            <td class="tableleft">新密码</td>
            <td><input type="password" id="newPwd" name="newPwd"/></td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="button" id="submit-button" class="btn btn-primary">修改</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    $("#submit-button").click(function () {
        var id = $("#id").val();
        var password = $("#password").val();
        var newPwd = $("#newPwd").val();
        var param = "id="+id +  "&password=" + password + "&newPwd=" + newPwd;
        $.ajax({
            url: "/user/changePwd",
            type: "post",
            async: true,
            data: param,
            success: function (res) {
                if (res.success) {
                    alert(res.message)
                    window.location.href = "/user/pwd";
                } else {
                    alert(res.message);
                    window.location.href = "/user/pwd";
                }
            }, error: function (e) {
                alert(e)
                window.location.href = "/user/pwd";
            }
        });
    });
</script>
</html>